<template>
	<view class="content">
		<view class="cui_fahuo" v-if="is_show==1">
			<view class="uni-flex uni-flex-align uni-flex-center">
				<image src="../../static/success.png" mode="" style="width: 100rpx;height: 100rpx;"></image>
			</view>
			<view class="wenzi">订单支付成功</view>
			<view class="uni-flex uni-flex-align uni-flex-center">
				<button  class='btn' open-type="launchApp" :app-parameter="type==1?'0000':type==2?'2222':type==3?'3333':'4444'" binderror="launchAppError">返回APP</button>
			</view>
		</view>
		<view class="cui_fahuo" v-if="is_show==2">
			<view class="uni-flex uni-flex-align uni-flex-center">
				<image src="../../static/fail.png" mode="" style="width: 100rpx;height: 100rpx;"></image>
			</view>
			<view class="wenzi">订单支付失败</view>
			<view class="uni-flex uni-flex-align uni-flex-center">
				<button  class='btn' style="bottom: 17vh;" @click="wei_login">继续支付</button>
				<button  class='btn' open-type="launchApp" :app-parameter="type==1?'0000':type==2?'2222':type==3?'3333':'4444'" binderror="launchAppError">返回APP</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id:'',
				data:'',
				is_show:0,
				type:'',
				user_id:''
			}
		},
		onLoad(e) {
			this.id=824
			this.type=2
			this.user_id = 1
			this.wei_login()
			// if(e.id){
			// 	this.id =e.id
			// 	this.type=e.type
			// 	this.user_id = e.user_id
			// 	this.wei_login()
			// }
			
		},
		methods: {
			wei_login(){
				let that = this
				uni.login({
					provider: 'weixin',
					success: (res) => {
						let data = {code: res.code,order_id:that.id,type:that.type}
						console.log(data)
						that.tui.request("api.wxapp/hf_session", "POST", {uuid:that.user_id,code: res.code}, false, false, false).then((res) => {
							console.log(res)
							if(res.code==1){
								that.tui.request("api.hf/payment", "POST", data, false, false, true).then((dds) => {
									console.log(dds)
									if(dds.code==1){
										that.data=dds.data.data.pay_info
										that.go_zhifu()
									}
									
								}).catch((res) => {
								})
							}
							
						}).catch((res) => {
						})
						
					},
				});
			},
			go_zhifu(){
				let that = this
				let data = that.data
				uni.requestPayment({
					timeStamp: data.timeStamp,
					nonceStr: data.nonceStr,
					package: data.package,
					signType: data.signType,
					paySign: data.paySign,
				    success: function (res) {
				        console.log('success:' + JSON.stringify(res));
						that.is_show = 1
				    },
				    fail: function (err) {
				        console.log('fail:' + JSON.stringify(err));
						that.is_show = 2
				    }
				});
			},
		}
	}
</script>

<style lang="scss">
	.cui_fahuo{padding: 100rpx 0;text-align: center;
		.wenzi{font-weight: bold;font-size: 32rpx;margin-top:40rpx;}
		.btn{padding: 0 50rpx;line-height: 80rpx;height: 80rpx;position: fixed;bottom: 10vh;width: 700rpx;margin-left: 25rpx;background: #333;color: #fff;font-size: 28rpx;}
		.wuliu{background: #fff;color: #333;border: 1px solid #333;}
	}
</style>
